class Solution
{
public:
    ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2)
    {
        if (pHead1 == NULL || pHead2 == NULL) return NULL;
        struct ListNode* pA = pHead1, * pB = pHead2;
        while (pA != pB)
        {
            pA = pA == NULL ? pHead2 : pA->next;
            pB = pB == NULL ? pHead1 : pB->next;
        }

        return pA;
    }
};